import {
    reqHostpitalInfo, reqUploadHospitalInfo, reqHospitalDoctorList, reqDeleteDoctor, reqReturnDoctor,
    reqHospitalPag
} from "@/api"
// state：仓库存储数据的地方
const state = {
    // 医院信息
    hospitalInfo: {},
    // 医院负责人信息
    hospitalManagerInfo: {},
    // 医生信息
    doctorList: [],
    // 医院列表
    hospitalList: []
}
// mutations：修改state的唯一手段，因此第一个参数必须是state，第二个参数为将要修改的数据
const mutations = {
    setHostpitalInfo(state, res) {
        state.hospitalInfo = res
    },
    setHostpitalManagerInfo(state, res) {
        state.hospitalManagerInfo = res
    },
    setDoctorList(state, res) {
        state.doctorList = res
    },
    setHospitalList(state, res) {
        state.hospitalList = res
    }
}
// action：书写业务逻辑（method方法）
const actions = {
    // 获取医院信息
    async getHostpitalInfo({ commit }) {
        let res = await reqHostpitalInfo()
        if (res.success) {
            commit("setHostpitalInfo", res.data.hospitalInfo)
            commit("setHostpitalManagerInfo", res.data.hospitalManagerInfo)
        }
        return res
    },
    // 更新医院信息
    async uploadHospitalInfo({ commit }, data) {
        let res = await reqUploadHospitalInfo(data)
        if (res.success) commit("setHostpitalInfo", res.data)
        return res
    },
    // 医院管理员获取医生列表
    async getHospitalDoctorList({ commit }, data) {
        let res = await reqHospitalDoctorList(data)
        if (res.success) commit("setDoctorList", res.data.doctorList)
        return res
    },
    // 删除医生
    async deleteDoctor({ commit }, data) {
        return await reqDeleteDoctor(data)
    },
    // 恢复医生
    async returnDoctor({ commit }, data) {
        return reqReturnDoctor(data)
    },
    // 分页获取医院列表
    async getHospitalPag({ commit }, data) {
        let res = await reqHospitalPag(data)
        if (res.success) commit("setHospitalList", res.data.hospitalList)
        return res
    }




}
// getters：计算属性
const getters = {

}

export default {
    state,
    mutations,
    actions,
    getters
}